<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
include("ListResult.php");
$arrFd = array(0 => "ID", 0 => "HostName");
$arrOd = array(0 => "ASC", 1 => "DESC");
$intFd = (int)$_data["OrderField"];
$intOd = (int)$_data["OrderBy"];
if($intFd < 0 || $intFd > 1)$intFd = 1;
if($intOd < 0 || $intOd > 1)$intFd = 1;
$strSQL = $strSQL." order by ".$arrFd[$intFd]." ".$arrOd[$intOd]." limit ".(($intPageNow-1)*$intPageNo).",".$intPageNo." ";
//print $strSQL;

if(!$RS = PMA_mysql_query($strSQL, $$_Conn)){
	$GLOBALS["errormessage"] = $_strVirtualHost["ErrMessage"]."1";//"系統發生錯誤, 請連絡工程師！";
	$GLOBALS["errorhidden"] = "\n Error: ".PMA_mysql_error($$_Conn).",\nSQL: ".$strSQL.",\nLine: ".__LINE__.",\nPage: ".__FILE__;
	ErrMsgOutputHTML("Error", "", 1);
}
$arrHost = array();
$strDirectorID = "0";
while($Rows = PMA_mysql_fetch_object($RS)){
	$arrHost[$Rows -> ID] = $Rows;
	if($Rows -> DirectID != "")$strDirectorID .= ",".$Rows -> DirectID;
}

//找出所有 總監的 帳號
$strSQL = "select * from `bet_Member` where ID in (".$strDirectorID.")";
if(!$RS = PMA_mysql_query($strSQL, $$_Conn)){
	$GLOBALS["errormessage"] = $_strVirtualHost["ErrMessage"]."2";//"系統發生錯誤, 請連絡工程師！";
	$GLOBALS["errorhidden"] = "\n Error: ".PMA_mysql_error($$_Conn).",\nSQL: ".$strSQL.",\nLine: ".__LINE__.",\nPage: ".__FILE__;
	ErrMsgOutputHTML("Error", "", 1);
}

$arrDirector = array();
$arrDirectorIsLock = array();
while($Rows = PMA_mysql_fetch_object($RS)){
	$arrDirector[$Rows -> ID] = $Rows -> Account;
	$arrDirectorIsLock[$Rows -> ID] = $Rows -> isLock;
}

$fp = @file($strTemplatePath."List.html");
$fp = implode("", $fp);
$fp = setHTMLCharset($fp);

while(list($k, $v) = each($_strVirtualHost)){
	$fp = str_replace("{".$k."}", $v, $fp);
}

$strCon = "";
//分頁下拉清單
for($i = 1; $i <= $intTotalPage; $i++){
	if($i == $intPageNow){
		$strCon .= "<option value='".$i."' selected>".$i."</option>\n";
	}else{
		$strCon .= "<option value='".$i."'>".$i."</option>\n";
	}
}
$fp = str_replace("{PageSelectOpion}", $strCon, $fp);
$fp = str_replace("{intTotalPage}", $intTotalPage, $fp);
$fp = str_replace("{intPageNow}", $intPageNow, $fp);
$fp = str_replace("{intTotal}", $intTotal, $fp);
$fp = str_replace("{OrderField}", $intFd, $fp);
$fp = str_replace("{OrderField".$intFd."}", "selected", $fp);
$fp = str_replace("{OrderBy}", $intOd, $fp);
$fp = str_replace("{OrderBy".$intOd."}", "selected", $fp);

//內容清單
$strCon = "";
$strTmp = "";
preg_match("/<!-- @ Content Start @ \/\/-->(.+)<!-- @ Content End @ \/\/-->/s", $fp, $arrCon);

foreach($arrHost as $intID => $Rows){
	$arrDID = split(",", $Rows -> DirectID);
	$arrDt = array();
	foreach($arrDID as $intDID){
		$strStyle = "";
		if($arrDirectorIsLock[$intDID] == '1'){	//停用
			$strStyle = "background-color: #000000; color: #FFFFFF";
		}elseif($arrDirectorIsLock[$intDID] == '2'){ //停壓
			$strStyle = "background-color: #FF0000; color: #FFFFFF";
		}

		if($arrDirector[$intDID] != "")$arrDt[] = '<a style="'.$strStyle.'">'.$arrDirector[$intDID].'</a>';
	}

	$strTmp = str_replace("{ShowHostName}", $Rows -> HostName, $arrCon[1]);
	$strTmp = str_replace("{ShowDirector}", join("<br />", $arrDt), $strTmp);
	$strTmp = str_replace("{ShowMemo}", $Rows -> Memo, $strTmp);
	$strTmp = str_replace("{ShowID}", $Rows -> ID, $strTmp);
	$strCon .= $strTmp."\n";
}
$fp = preg_replace("/<!-- @ Content Start @ \/\/-->.+<!-- @ Content End @ \/\/-->/s", $strCon, $fp);

//輸出
WebOutputHTML($fp, 1);
?>